package org.csu.onlineedubackend.controller;

import lombok.extern.slf4j.Slf4j;
import org.csu.onlineedubackend.dto.ChapterWithLessonsDTO;
import org.csu.onlineedubackend.entity.Course;
import org.csu.onlineedubackend.result.CommonResponse;
import org.csu.onlineedubackend.result.ResponseCode;
import org.csu.onlineedubackend.service.ChapterService;
import org.csu.onlineedubackend.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/teacher")
@Slf4j
public class StudentTeacherChapterController {

    @Autowired
    private ChapterService chapterService;
    
    @Autowired
    private CourseService courseService;

    /**
     * 获取课程的章节和课时
     * GET /api/teacher/courses/{courseId}/chapters
     */
    @GetMapping("/courses/{courseId}/chapters")
    public List<ChapterWithLessonsDTO> getChaptersWithLessons(@PathVariable Integer courseId) {
        log.info("获取课程章节和课时 - 课程ID: {}", courseId);
        
        // 获取章节和课时
        List<ChapterWithLessonsDTO> chapters = chapterService.getChaptersWithLessons(courseId);
        log.info("获取课程章节和课时成功 - 课程ID: {}, 章节数: {}", courseId, chapters.size());
        
        return chapters;
    }
} 